﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace QD.Config
{
    public class Configs : ConfigsBase
    {
        private static Configs _instance;
        public static Configs Instance()
        {
            if (_instance == null)
            {
                _instance = new Configs();
            }
            return _instance;
        }

        protected override string ConfigFilePath
        {
            get { return HttpContext.Current.Server.MapPath("/Config/Config.config"); }
        }

        protected override Type ConfigInfoType
        {
            get { return typeof(IConfig); }
        }

        public Configs()
        {
            Load();
        }

        private ConfigInfo _config;

        public ConfigInfo GetConfig()
        {
            return _config;
        }

        protected void Load()
        {
            try
            {
                _config = (ConfigInfo)LoadConfig();
            }
            catch (Exception)
            {
                _config = new ConfigInfo();
            }
        }


        public void Save(ConfigInfo config)
        {
            try
            {
                SaveConfig(config);
                Load();
            }
            catch (Exception)
            {

            }
        }
    }
}
